#include "GLError.h"

std::vector<std::string> GLError::_errors;

GLError::GLError(const std::string& message):runtime_error(message)
{
}

std::string GLError::message()
{
	std::string result=runtime_error::what();
	std::string errorList=trace();
	
	result+="\n"+errorList;

	return result;
}

//Create a list of all errors that have been recorded
std::string GLError::trace()
{
	std::string result="";

	for (unsigned long i=0;i<GLError::_errors.size();++i)
		result+=GLError::_errors.at(i)+"\n";

	return result;
}

int GLError::checkErrors()
{
	GLenum e;
	int c=0;

	//Limit the loop to 10 iterations, in case calling glGetError() itself generates an error
	while (((e=glGetError()) != GL_NO_ERROR) && (c<10))
	{
		//std::string error=
		//_errors.push_back(error);
		std::cout << (char*)gluErrorString(e) << std::endl;
		c++;
	}

	return c;
}


